#include <iostream>
#include <future>
#include <thread>
#include <memory>

int Sub(int num1, int num2)
{
    std::cout << "减法开始操作" << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(3));
    return num1 - num2;
}
int main()
{
    // std::packaged_task<int(int, int)> task(Sub);  //是一个封装的任务
    // task(10, 20); 像函数一样，但是又不完全一样
    // std::thread thr(task, 10, 23);
    // std::async(std::launch::async, task, 12, 23);

    //但是可以用一个指针对象
    std::shared_ptr<std::packaged_task<int(int, int)>> ptask = 
        std::make_shared<std::packaged_task<int(int, int)>>(Sub);

    std::future<int> fu = ptask->get_future();
    
    std::thread thread1([ptask](){
        (*ptask)(10, 20);
    });
    std::cout << fu.get() << std::endl;
    thread1.join();
    return 0;
}
